#!/usr/bin/python
# -*- coding: UTF-8 -*- 

import wx
import os
from Common.listDir import *

## @detail MainFrame主界面窗口类
class MainFrame(wx.Frame):
    def __new__(cls,listData,delegate):
        # 关键在于这，每一次实例化的时候，我们都只会返回这同一个instance对象
        if not hasattr(cls, 'instance'):
            cls.instance = super(MainFrame, cls).__new__(cls)
        return cls.instance

    def __init__(self,listData,delegate):
        wx.Frame.__init__(self, None, wx.ID_ANY,  'FileDialog2 study', pos=wx.DefaultPosition,
            size=(600, 400), style=wx.DEFAULT_FRAME_STYLE)

        panel = wx.Panel(self)
        #panel.SetBackgroundColour('#4f5049')

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox1 = wx.BoxSizer(wx.HORIZONTAL) #水平方向添加约束,约束之间可以叠加

        label = wx.StaticText(panel, -1, u"当前选择要生成的帖纸类型:")
        hbox1.Add(label)

        ch1=wx.ComboBox(panel,choices=listData)
        hbox1.Add(ch1,1,wx.LEFT|wx.RIGHT,10)
        vbox.Add(hbox1,0,wx.TOP|wx.LEFT,10)
        #第二行
        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        label2= wx.StaticText(panel, -1, u"当前选择要生成的帖纸名字:")
        hbox2.Add(label2,0,wx.LEFT,10)
       
        textBox = wx.TextCtrl(panel, 0,)
        hbox2.Add(textBox,0,wx.LEFT,10)
        vbox.Add(hbox2,0,wx.TOP,20)
        # # # panel.SetSizer(sizer2)

        hbox3 = wx.BoxSizer(wx.HORIZONTAL)
        btn = wx.Button(panel,-1,"点击上传zip")
        #btn.Show(False) 控制显示
        btn.Bind(wx.EVT_BUTTON, lambda evt,mark="hehe":self.OnClicked(evt,"hehe"))
        hbox3.Add(btn,0,wx.LEFT,400)
        vbox.Add(hbox3,0,wx.TOP,-66)

        hbox4 = wx.BoxSizer(wx.HORIZONTAL)
        label3= wx.StaticText(panel, -1, u"")
        hbox4.Add(label3,0,wx.LEFT,400)
        vbox.Add(hbox4,0,wx.TOP,-36)

        hbox5 = wx.BoxSizer(wx.HORIZONTAL)
        lblList = ['yes', 'no']
        rbox = wx.RadioBox(panel,label = '是否有特殊资源', choices = lblList ,
   majorDimension = 1, style = wx.RA_SPECIFY_ROWS)
        rbox.SetSelection(1)
        rbox.Bind(wx.EVT_RADIOBOX,self.onRadioBox)
        hbox5.Add(rbox)
       

        label4= wx.StaticText(panel, -1, u"")
        hbox5.Add(label4,0,wx.TOP|wx.LEFT,20)
        #label4.Show(False)
        vbox.Add(hbox5,0,wx.TOP|wx.LEFT,20)
        # self.CreateStatusBar()
        # self.__BuildMenus() 
        hbox6 = wx.BoxSizer(wx.HORIZONTAL)
        btn2 = wx.Button(panel,-1,"      \n生成贴纸\n     ",size=(100,60))
        btn2.Bind(wx.EVT_BUTTON, lambda evt,mark="hehe":self.OnClicked2(evt,"hehe"))
        hbox6.Add(btn2,0,wx.ALIGN_CENTER_HORIZONTAL,0)
        vbox.Add(hbox6,0,wx.ALIGN_CENTER_HORIZONTAL,0)

        Promodel =  listAllDir("./ProductSticker")
        if len(Promodel)<1:
            Promodel =  listAllDir(os.path.dirname(__file__)+"/ProductSticker")
        print(Promodel)
        hbox7 = wx.BoxSizer(wx.HORIZONTAL)
        label5= wx.StaticText(panel, -1, u"当前选择要上传的贴纸:")
        hbox7.Add(label5,0,wx.TOP,20)
        
        ch2=wx.ComboBox(panel,choices=Promodel)
        hbox7.Add(ch2,0,wx.TOP|wx.LEFT,15)
        vbox.Add(hbox7,0,wx.TOP|wx.LEFT,10)

        hbox8 = wx.BoxSizer(wx.HORIZONTAL)
        btn3 = wx.Button(panel,-1,"      \n上传贴纸\n     ",size=(100,60))
        hbox8.Add(btn3,0,wx.TOP|wx.RIGHT,20)

        btn4 = wx.Button(panel,-1,"      \n打包贴纸\n     ",size=(100,60))
        hbox8.Add(btn4,0,wx.TOP|wx.RIGHT,20)
        vbox.Add(hbox8,0,wx.ALIGN_CENTER_HORIZONTAL,0)
        # textBox = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE, size =(-1, 300))    
        # sizer = wx.BoxSizer(wx.HORIZONTAL)
        # sizer.Add(label, 0, wx.ALL|wx.ALIGN_CENTRE)
        # sizer.Add(textBox, 1, wx.ALL|wx.ALIGN_CENTRE)
        self.__comboBox = ch1
        self.__procomboBox = ch2
        self.__textBox = textBox
        self.__staticZipLabel = label3
        self.__resLabel = label4
        self.__paths = []
        self.__rbox = rbox
        self.__panel = panel
        self.__delegate = delegate
        # self.SetSizerAndFit(sizer)
        panel.SetSizer(vbox)
    def getStickerName(self):
        return self.__textBox.GetValue()
    def getPaths(self):
        return self.__paths
    def getStickerType(self):
        return self.__comboBox.GetValue()
    def getProductName(self):
        return self.__procomboBox.GetValue()
    def OnClicked(self, event,parm): 
        btn = event.GetEventObject().GetLabel() 
        print("Label of pressed button = ", self.__comboBox.GetValue())
        self.__MultipleSelectFiles()
    def OnClicked2(self, event,parm):
        #wx.MessageBox("Success", "Message" ,wx.OK|wx.ICON_INFORMATION)
        if  hasattr(self.__delegate, 'createSticker'):
            self.__delegate.createSticker()
        dial = wx.MessageDialog(self.__panel,'General completed','success',wx.OK)
        dial.ShowModal()
    ## @detail wx.FileDialog style：wx.FD_OPEN | wx.FD_MULTIPLE
    def __MultipleSelectFiles(self):
        #"Dicom (*.dcm)|*.dcm|" "All files (*.*)|*.*"
        filesFilter = "*.zip"
        fileDialog = wx.FileDialog(self, message ="多文件选择", wildcard = filesFilter, style = wx.FD_OPEN|wx.FD_MULTIPLE)
        dialogResult = fileDialog.ShowModal()
        if dialogResult !=  wx.ID_OK:
            return
        paths = fileDialog.GetPaths()
        self.__staticZipLabel.SetLabel('')
        for path in paths:
            self.__paths.append(path)
            oriPath = self.__staticZipLabel.GetLabel()
            oriPath = oriPath+"\n"+path
            self.__staticZipLabel.SetLabel(oriPath)
    def onRadioBox(self,e):
        if self.__rbox.GetStringSelection()=="yes":
            #pass
            self.__resLabel.SetLabel("res")
        else:
            self.__resLabel.SetLabel("")

        
        